package com.link.base.base.order.service;

import com.alibaba.fastjson.JSONObject;
import com.link.base.base.order.model.*;
import com.link.base.base.order.model.*;
import com.link.base.base.product.model.Product;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.BasicServiceException;

import java.util.List;
import java.util.Map;

/**
 * @author yrf
 * @date unknown
 * @comments 订单服务
 */
public interface SaleOrderService extends BasicService<SaleOrder> {

//  //走siebel接口
//  public SaleOrder insertByWS(SaleOrder record) throws Exception;
//
//  //走siebel接口
//  public SaleOrder updateByWS(SaleOrder record) throws Exception;

    /**
     * 更新提交订单
     *
     * @param record 订单
     * @param selectUserId
     * @return
     * @throws Exception
     */
    public void orderCommitUpdate(SaleOrder record, Long selectUserId) throws Exception;

    /**
     * 取消订单
     * @param record 订单
     * @throws BasicServiceException
     */
    public void cancelSaleOrderUpdate(SaleOrder record) throws BasicServiceException;

    /**
     * 跟新订单上的客户
     * @param record 订单
     * @throws BasicServiceException
     */
    public void orderAcctIdUpdate(SaleOrder record) throws BasicServiceException;

    /**
     * 更新说明
     * @param record 订单
     * @throws BasicServiceException
     */
    public void commentsUpdate(SaleOrder record) throws BasicServiceException;

    /**
     * unknown
     * @param record 订单
     * @return double
     * @throws BasicServiceException
     */
    public Double countTotalCash(SaleOrder record) throws BasicServiceException;

    /**
     * 计算该订单的总金额
     *
     * @param record 销售订单ID
     * @return 订单
     * @throws BasicServiceException
     */
    public SaleOrder querySaleOrderTotalAmount(SaleOrder record) throws BasicServiceException;

    /**
     * 发货完成方法
     *
     * @param record
     * @throws Exception
     */
    public void sendComplete(SaleOrder record) throws Exception;

    /**
     * 订单审核方法
     *
     * @param objectId
     * @param param1
     * @param param2
     * @param param3
     * @param param4
     * @param param5
     * @throws Exception
     */
    public void approvalUpdateOrderStatus(Long objectId, String param1, String param2, String param3, String param4,
                                          String param5) throws Exception;

    /**
     * 订单审核其他操作方法
     *
     * @param objectId
     * @param attr1
     * @param attr2
     * @param attr3
     * @param attr4
     * @param attr5
     * @param attr6
     * @param attr7
     * @param attr8
     * @param attr9
     * @param attr10
     * @throws Exception
     */
    public void approvalUpdateOrderInfo(Long objectId, String attr1, String attr2, String attr3, String attr4, String attr5,
                                        String attr6, String attr7, String attr8, String attr9, String attr10) throws Exception;

    /**
     * <p>查询订单</p>
     *
     * @author yrf
     * @param id
     * @return 订单
     * @throws Exception
     */
    public SaleOrder queryOneById(Long id) throws Exception;

    /**
     * <p>订单审核通过</p>
     *
     * @author yrf
     * @param order
     * @throws Exception
     */
    public void orderApprovedUpdate(SaleOrder order) throws Exception;

    /**
     * <p>订单确认发货</p>
     *
     * @author yrf
     * @param order
     * @throws Exception
     */
    public void orderConfirmSendUpdate(SaleOrder order) throws Exception;

    /**
     * <p>设置是为已付款</p>
     *
     * @author yrf
     * @param order
     * @throws Exception
     */
    public void paidUpdate(SaleOrder order) throws Exception;

    /**
     * 到货确认
     *
     * @param record
     * @return int
     */
    public int arrivedUpdate(SaleOrder record);

    /**
     * <p>买方确认到货</p>
     *
     * @author yrf
     * @param record
     * @return int
     */
    public int confirmArrivedUpdate(SaleOrder record);

    /**
     * 应用政策1
     *
     * @param record
     * @throws Exception
     */
    public void applyPolicy(SaleOrder record) throws Exception;

    /**
     * 应用政策2
     *
     * @param saleOrder
     * @throws Exception
     */
    public void applyPolicyTwo(SaleOrder saleOrder) throws Exception;

    /**
     * <p>修改订单状态</p>
     *
     * @author yrf
     * @param order
     * @return int
     * @throws Exception
     */
    public int orderStatusUpdate(SaleOrder order) throws Exception;

    /**
     * 查询区域订单情况
     *
     * @param order 订单
     * @return list
     * @throws Exception
     */
    public List<SaleOrder> querySalesOrderOfDistrictPage(SaleOrder order) throws Exception;

    /**
     * 查询区域销量情况
     * @param order 订单
     * @return list
     * @throws Exception
     */
    public List<SaleOrder> querySalesOfDistrictPage(SaleOrder order) throws Exception;

    /**
     * 获得区域销量报表html
     *
     * @param list 订单列表
     * @return String 报表html
     * @throws Exception
     */
    public String getSalesReportHtml(List<SaleOrder> list) throws Exception;

    /**
     * 获得区域订单报表html
     *
     * @param list 订单列表
     * @return String 定单报表html
     * @throws Exception
     */
    public String getSalesOrderReportHtml(List<SaleOrder> list) throws Exception;

    /**
     * 更新添加定单头和行
     * @param order 定单
     * @return 定单
     * @throws Exception
     */
    public SaleOrder upsertHeadAndLine(SaleOrder order) throws Exception;


    /**
     * 订单记录数统计
     * @param order 定单
     * @return int
     * @throws Exception
     */
    public int selectCountByacctId(SaleOrder order) throws Exception;

    /**
     * 校验客户的可售权限
     *
     * @auther HuangLJ
     * @param saleOrder
     * @return String
     * @throws Exception
     */
    public String checkCanSale(SaleOrder saleOrder) throws Exception;

    /**
     * 校验客户的资金账户
     * @auther HuangLJ
     * @param saleOrder
     * @return String
     * @throws Exception
     */
    public String checkDealerAccount(SaleOrder saleOrder) throws Exception;

    /**
     * HuangLJ
     * 审核订单
     * 当前端点击审核订单的时候，校验订单的可售权限，生成政策信息，校验库存，校验金额
     * 如果校验通过，则生成资金占用记录。修改付款状态为已付款，设置订单状态为已审核
     *
     * @param saleOrder 订单对象
     * @return 订单对象
     * @throws Exception
     */
    public void orderVerify(SaleOrder saleOrder) throws Exception;

    /**
     * HuangLJ 订单确认
     *
     * @param saleOrder 订单对象
     * @return String
     * @throws Exception 报错
     */
    public String confirm(SaleOrder saleOrder) throws Exception;

    /**
     * HuangLJ 订单确认
     *
     * @param saleOrder 订单对象
     * @return String
     * @throws Exception 报错
     */
    public String dmsConfirm(SaleOrder saleOrder) throws Exception;


    /**
     * HuangLJ
     * 审核提交
     * 当前端点击审核订单的时候，校验订单的可售权限，生成政策信息，校验库存，校验金额
     * 如果校验通过，则生成资金占用记录。修改付款状态为已付款，设置订单状态为已审核
     *
     * @param saleOrder 订单对象
     * @throws Exception
     */
    public void orderCommit(SaleOrder saleOrder) throws Exception;


    /**
     * HuangLJ
     * 订单完成
     *
     * @param saleOrder 订单对象
     * @throws Exception
     */
    public void complete(SaleOrder saleOrder) throws Exception;

    /**
     * Hlj 退货单更新状态 2018年06月04日
     *
     * @param saleOrder 订单对象
     * @throws Exception 报错
     */
    public void returnOrdUpdateStatus(SaleOrder saleOrder) throws Exception;

    /**
     * Hlj 退货订单退款 2018年06月04日
     *
     * @param saleOrder 订单对象
     * @throws Exception 报错
     */
    public void returnOrderRefund(SaleOrder saleOrder) throws Exception;

    /**
     * 各类型订单的出库和入库操作
     *
     * @author 何启谦
     * @param saleOrder     订单头,必须包含所有字段
     * @param orderItemList 订单行,必须包含所有字段
     * @param invtxnType    库存交易类型
     * @return 定单
     * @throws Exception
     */
    public SaleOrder outInInvtxn(SaleOrder saleOrder, List<SaleOrderItem> orderItemList, String invtxnType) throws Exception;

    /**
     * 检查和修改已到货数量，如果所有产品都到货完毕，则修改订单状态
     *
     * @author 何启谦
     * @param paramOrderItemList 订单行
     * @param invtxnType         库存交易类型
     * @return 定单
     * @throws Exception
     */
    public SaleOrder arrivedOrderItem(List<SaleOrderItem> paramOrderItemList, String invtxnType) throws Exception;


    /**
     * 付款
     * @param record 定单
     * @throws Exception
     */
    public void orderPayUpdate(SaleOrder record) throws Exception;

    /**
     * 企点新建订单
     * @param record 定单
     * @throws Exception
     */
    public void insertGuideOrder(SaleOrder record) throws Exception;

    /**
     * 提交订单
     * @param record 定单
     * @return 定单
     * @throws Exception
     **/
    public SaleOrder commitOrder(SaleOrder record) throws Exception;

    /**
     * 销售排名
     *
     * @param orderSaleRank
     * @return 销售排名
     * @throws Exception
     */
    public OrderSaleRank orderSaleRank(OrderSaleRank orderSaleRank) throws Exception;

    /**
     * 查询月销售数据看板
     *
     * @param orderAmountBoard
     * @return OrderAmountBoard 数据看板
     * @throws Exception
     */
    public OrderAmountBoard queryOrderAmountBoard(OrderAmountBoard orderAmountBoard) throws Exception;

    /**
     * 查询月销售业绩看板
     *
     * @param orderAmountBoard
     * @return OrderAmountBoard 数据看板
     * @throws Exception
     */
    public OrderAmountBoard queryMonthAchieveBoard(OrderAmountBoard orderAmountBoard) throws Exception;

    /**
     * app dms迁移过来的方法
     * @param record
     * @return int
     * @throws Exception
     */
    public int queryPurchaseMoreByAccntIdCount(SaleOrder record) throws Exception;

    /**
     * app dms迁移过来的方法SaleOrder
     * @param record
     * @return List
     * @throws Exception
     */
    public List<Product> queryPurchaseMoreByAccntId(SaleOrder record)
            throws Exception;

    /**
     * dms订单的提交，如果订单不存在则先新建订单
     * @auhtor lizt 20180522
     * @param record
     * @throws Exception
     */
    public void commitDmsOrder(SaleOrder record) throws Exception;

    /**
     * 订单根据支付记录更新状态
     * @param entity
     * @throws Exception
     */
    public void orderStatusUpdateByPayRecord(PayRecord entity) throws Exception;

    /**
     * 校验扫码所得优惠券是否适用所选订单
     * @param saleOrder
     * @return
     * @throws Exception
     */
    public Map<String,Object> couponsCheckOrder(SaleOrder saleOrder) throws Exception;

    /**
     * 订单支付失败后 修改优惠券状态为已领取
     * @author lujiang
     * @param record
     * @throws Exception
     */
    void collectRecordUpdate(SaleOrder record) throws Exception;

    /**
     * 订单取消后改变订单使用的优惠券状态
     * @param record
     * @throws Exception
     */
    void couponsUpdateStatus(SaleOrder record) throws Exception;

    /**
     * 查看特定时间内下未付款的订单（30分钟，15分钟），设置取消订单
     * @return
     * @throws Exception
     */
    Map<String,Object> queryOrder() throws Exception;

    /**
     * 校验订单是否过来规定付款时间限定
     * @param saleOrder
     * @return
     * @throws Exception
     */
    Map<String,Object> checkOrderStatus(SaleOrder saleOrder) throws Exception;

    /**
     * 生成忠诚度交易
     * @author 路江
     * @param record
     * @throws Exception
     */
    void createTransactionRecord(SaleOrder record) throws Exception;

    /**
     * <p>深度复制dms订单</p>
     *
     * @author yrf
     * @param order
     * @return
     */
    SaleOrder deepCopyDmsOrder(SaleOrder order) throws Exception;

    /**
     * 根据录入结果生成相应订单
     * @author 姚江漪
     * @date 2019/08/17 15:03
     */
    public void genInteractionOrder(JSONObject jsonObject) throws Exception;

    /**
     *  根据奖励记录创建奖励订单
     * @author yaopengjian
     * @param entity 奖励记录
     * @return void
     * @date 2019/12/9
     */
    void createRewardOrder(SaleOrder entity) throws Exception;
}
